import Control.Monad.State

type Counter = Int

-- 增加计数器
increment :: State Counter ()
increment = modify (+1)

-- 获取并增加
getAndIncrement :: State Counter Int
getAndIncrement = do
    count <- get
    put (count + 1)
    return count

main :: IO ()
main = do
    let (result, finalState) = runState computation 0
    print $ "Result: " ++ show result ++ ", Final state: " ++ show finalState
  where
    computation = do
        increment
        increment
        val <- getAndIncrement
        increment
        return val